<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实时时钟</title>
</head>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        setInterval(() => {
            let now = new Date();
            let time = now.toLocaleTimeString('chinese', { hour12: false })
            let date = now.toLocaleDateString()
            date = date.split('/')
            date = `${date[0]}年${date[1]}月${date[2]}日`;
            let week = now.getDay()
            weekArr = ['一', '二', '三', '四', '五', '六', '日']
            week = `星期${weekArr[week - 1]}`
            let weekNode = document.querySelectorAll('.right p')[0]
            let dateNode = document.querySelectorAll('.right p')[1]
            render(weekNode, week)
            render(dateNode, date)
            render('.left p', time)
        }, 1000)
    })
    function render(Node, data) {
        let node;
        if (Node instanceof HTMLElement) {
            node = Node
        } else {
            node = document.querySelector(Node)
        }
        node.innerHTML = data
    }
</script>

<body>
    <div id="root">
        <div class="wrapper">
            <span class="left">
                <p>15:03:44</p>
            </span>
            <span class="right">
                <p>星期五</p>
                <p>2022年08月12日</p>
            </span>
        </div>
    </div>
    </div>

    <style>
        * {
            margin: 0;
            padding: 0;
            /* border: 1px red solid; */
        }

        #root {
            height: 100%;
        }

        .wrapper {
            height: 70px;
            width: 300px;
            margin: 175px auto;
            background-color: #b8d4f5;
            position: relative;
            border-radius: 5%;
        }

        .left,
        .right {
            width: 50%;
            height: 100%;
            float: left;
        }

        p {
            font-family: LiSu;
        }

        .left p {
            height: 80px;
            line-height: 80px;
            text-align: center;
            font-size: 36px;
            font-family: 'Lucida Grande';
            color: #263950;
            font-weight: bold
        }

        .right p:first-child {
            font-size: x-large;
            padding-top: 10px;
        }

        .right p {
            text-align: center;
            font-weight: bold;
            color: #263950;
        }
    </style>

</body>

</html>